define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'cyclopedia/disease/index' + location.search,
                    add_url: 'cyclopedia/disease/add',
                    edit_url: 'cyclopedia/disease/edit',
                    del_url: 'cyclopedia/disease/del',
                    multi_url: 'cyclopedia/disease/multi',
                    import_url: 'cyclopedia/disease/import',
                    table: 'disease',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'disease_id',
                sortName: 'weight',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'disease_id', title: 'ID'},
                        {field: 'name', title: __('Name'), operate: 'LIKE'},
                        {field: 'first_name', title: '首字母', operate: 'LIKE'},
                        {field: 'office.type_name', title: __('科室'), operate: 'LIKE'},
                        // {field: 'overview', title: __('Overview')},
                        // {field: 'reason', title: __('Reason')},
                        // {field: 'symptom', title: __('Symptom')},
                        // {field: 'cure', title: __('Cure')},
                        // {field: 'prevent', title: __('Prevent')},
                        {field: 'hospital.name', title: __('Recommend_h'), operate: 'LIKE',formatter: Table.api.formatter.flag},
                        {field: 'weight', title: __('Weight')},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'deteletime', title: __('Deteletime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            //胜诉
            $(".btn-process-1").click(function(){
                // var ids = Table.api.selectedids(table);
                layer.confirm('确定要更新数据吗?', {btn: ['是','否'] },
                    function(index){
                        layer.close(index);
                        $.post("cyclopedia/disease/get_name", {},function(response){
                            if(response.code == 1){
                                Toastr.success(response.msg);
                                $(".btn-refresh").trigger('click');
                            }else{
                                Toastr.error(response.msg);
                            }
                        }, 'json');
                    },
                    function(index){
                        layer.close(index);
                    }
                );
            });

            $(".btn-br").click(function(){
                // var ids = Table.api.selectedids(table);
                layer.confirm('确定要更新数据吗?', {btn: ['是','否'] },
                    function(index){
                        layer.close(index);
                        $.post("cyclopedia/disease/update_br", {},function(response){
                            if(response.code == 1){
                                Toastr.success(response.msg);
                                $(".btn-refresh").trigger('click');
                            }else{
                                Toastr.error(response.msg);
                            }
                        }, 'json');
                    },
                    function(index){
                        layer.close(index);
                    }
                );
            });
            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
